package com.hh.ListNodeQuestions;

/**
 * @Author hanghao
 * @Date 2023/6/28 15:26
 * @Version 1.0
 * easy
 * 移除链表元素       (递归函数系列)
 */

public class No203 {
    public ListNode removeElements(ListNode head, int val) {
        if(head == null) {
            return head;
        }
        ListNode dummy = new ListNode(0, head);
        ListNode pre = dummy;
        ListNode cur = head;
        while (cur != null) {
            if (cur.val == val) {
                pre.next = cur.next;
            } else {
                pre = cur;
            }
            cur = cur.next;
        }
        return dummy.next;
    }
}
